package it.unical.mat.aec.gui;

import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;

public class IconButton {
	
	public static JLabel getLabelButton(String imageIconName, Dimension dim, String toolTipText,final LabelButtonEvent event){
		IconImage icon=new IconImage(imageIconName, dim);
		JLabel button=new JLabel(icon.getIcon());
		button.setPreferredSize(dim);
		button.setToolTipText(toolTipText);
		button.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {
				((JComponent) e.getComponent()).setBorder(BorderFactory.createBevelBorder(0));
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				((JComponent) e.getComponent()).setBorder(BorderFactory.createBevelBorder(1));								
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				((JComponent) e.getComponent()).setBorder(null);				
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				((JComponent) e.getComponent()).setBorder(BorderFactory.createBevelBorder(0));
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				if(event!=null)
					event.event();
			}
		});
		return button;
	}
	
	
}
